package jch.learn.java.advanced.chapter2_InputAndOutput;

import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Iterator;

public class TestPath {

    public static void main(String[] args) {
        // 静态的Paths.get方法接收一个或多个字符串，并将它们用默认的文件系统的路径分隔符(Unix文件系统:/,Windows文件系统:\)连接起来。
        // 然后解析它连接起来的结果，若不是给定的文件系统中的合法路径，则会抛出InvalidPathException异常；若是则返回一个Path对象。
        Path testPath = Paths.get("F:/learnSpace/java-learn-demo/java-core-technology-advanced", "src/main/resources");
        Iterator<Path> pathIterator = testPath.iterator();
        while (pathIterator.hasNext()) {
            Path path = pathIterator.next();
            System.out.println(path.toString());
        }
        System.out.println("---");
        Path testPath1 = testPath.resolve(testPath);
        System.out.println(testPath1);
        System.out.println("---");
        Path testResolveSibling = testPath.resolveSibling("temp");
        System.out.println(testResolveSibling);
        System.out.println(testPath.normalize());
        System.out.println(testPath.toAbsolutePath());
        System.out.println(testPath.getParent());
        System.out.println(testPath.getFileName());
        System.out.println(testPath.getRoot());
        System.out.println(testPath.toFile());
    }
}
